home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / SHELL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-21  |  2.4 KB  |  128 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <OSBIND.H>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include "k_defs.h"
  13. #include "xa_globl.h"
  14. #include "shellwrt.h"
  15. #include "xa_defs.h"
  16.  
  17. unsigned long XA_shell_write(short clnt_pid, AESPB *pb)
  18. {
  19.     XA_CLIENT *client=Pid2Client(clnt_pid),*child;
  20.     short child_id;
  21.     
  22.     child_id=shell_write(pb->intin[0],pb->intin[1],pb->intin[2],(char*)pb->addrin[0],(char*)pb->addrin[1]);
  23.     pb->intout[0]=child_id;
  24.     
  25.     child=Pid2Client(child_id);
  26.     if (child)
  27.     {
  28.         child->parent=clnt_pid;
  29.     
  30.         if ((pb->intin[0]==1)&&(pb->intin[1]==1))
  31.         {
  32.             client->waiting_for=XAWAIT_CHILD;
  33.             return XAC_BLOCK;
  34.         }
  35.     }
  36.  
  37.     return XAC_DONE;
  38. }
  39.  
  40. unsigned long XA_shell_read(short clnt_pid, AESPB *pb)
  41. {
  42.     char *parent_name=(char*)pb->addrin[0];
  43.     char *tail=(char*)pb->addrin[1];
  44.     short f;
  45.     XA_CLIENT *client=Pid2Client(clnt_pid);
  46.     
  47.     sprintf(parent_name, "%s",Pid2Client(client->parent)->cmd_name);
  48.     
  49.     for(f=0; f<client->cmd_tail[0]+1; f++)
  50.         tail[f]=client->cmd_tail[f];
  51.     tail[f]=0;
  52.     
  53.     pb->intout[0]=1;
  54.     
  55.     return XAC_DONE;
  56. }
  57.  
  58. unsigned long XA_shell_find(short clnt_pid, AESPB *pb)
  59. {
  60.     char *kp=getenv("PATH");
  61.     char *fn=pb->addrin[0];
  62.     char path[128],cwd[200];
  63.     long handle;
  64.     short f=0,l,n;
  65.     XA_CLIENT *client=Pid2Client(clnt_pid);    
  66.  
  67. /* check the clients home path */
  68.     sprintf(path,"%s\\%s",client->home_path,fn);
  69.     handle=Fopen(path,0);
  70.     if (handle>0)
  71.     {
  72.         Fclose(handle);
  73.         sprintf(fn,"%s",path);
  74.         pb->intout[0]=1;
  75.         
  76.         return XAC_DONE;
  77.     }
  78.     
  79. /* check our PATH enviroment variable */
  80.     l=strlen(cwd);
  81.     sprintf(cwd,"%s",kp);
  82.     
  83.     while(f<l)
  84.     {                /* We understand ':', ';' and ',' as path seperators */
  85.         for(n=f; (cwd[n])&&(cwd[n]!=':')&&(cwd[n]!=';')&&(cwd[n]!=','); n++)
  86.             if (cwd[n]=='/') cwd[n]='\\';
  87.         
  88.         cwd[n]='\0';
  89.         
  90.         sprintf(path,"%s\\%s",cwd+f,fn);
  91.         handle=Fopen(path,0);
  92.         if (handle>0)
  93.         {
  94.             Fclose(handle);
  95.             sprintf(fn,"%s",path);
  96.             pb->intout[0]=1;
  97.  
  98.             return XAC_DONE;
  99.         }
  100.         f=n+1;
  101.     }
  102.  
  103. /* Last ditch - try the file spec on it's own */
  104.     handle=Fopen(fn,0);
  105.     if (handle>0)
  106.     {
  107.         Fclose(handle);
  108.         pb->intout[0]=1;
  109.         
  110.         return XAC_DONE;
  111.     }
  112.  
  113. /* Didn't find the file :( */
  114.     pb->intout[0]=0;
  115.     return XAC_DONE;
  116. }
  117.  
  118. unsigned long XA_shell_envrn(short clnt_pid, AESPB *pb)
  119. {
  120.     char **p=pb->addrin[0];
  121.     char *name=(char*)pb->addrin[1];
  122.     *p=getenv(name);
  123.     
  124.     pb->intout[0]=1;
  125.     
  126.     return XAC_DONE;
  127. }
  128.